﻿

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using MySql.Data.MySqlClient;

public class DAL_tbl_user_type
{
    public DAL_tbl_user_type()
    {

    }



    public List<tbl_user_type> select(int USER_TYPE_ID)
    {
        List<tbl_user_type> list = new List<tbl_user_type>();
        MySqlCommand cmd = new MySqlCommand();
        cmd.CommandText = "Select USER_TYPE_ID,USER_TYPE,IS_ACTIVE,CREATED_BY,CRETED_DATE,UPDATED_BY,UPDATED_DATE from tbl_user_type where USER_TYPE_ID=@USER_TYPE_ID";
        cmd.Parameters.AddWithValue("@USER_TYPE_ID", USER_TYPE_ID);
        DataTable dt = DBUtil.ExecuteDataTable(cmd);
        foreach (DataRow dr in dt.Rows)
        {
            list.Add(new tbl_user_type()
            {
                USER_TYPE_ID = Convert.ToInt32(dr["USER_TYPE_ID"]),
                USER_TYPE = dr["USER_TYPE"].ToString(),
                IS_ACTIVE = Convert.ToBoolean(dr["IS_ACTIVE"]),
                CREATED_BY = dr["CREATED_BY"].ToString(),
                CRETED_DATE = dr["CRETED_DATE"].toDateTimeWithoutError(),
                UPDATED_BY = dr["UPDATED_BY"].ToString(),
                UPDATED_DATE = dr["UPDATED_DATE"].toDateTimeWithoutError()
            });
        }

        return list;
    }



    public List<tbl_user_type> selectAll()
    {
        List<tbl_user_type> list = new List<tbl_user_type>();
        MySqlCommand cmd = new MySqlCommand();
        cmd.CommandText = "Select USER_TYPE_ID,USER_TYPE,IS_ACTIVE,CREATED_BY,CRETED_DATE,UPDATED_BY,UPDATED_DATE from tbl_user_type Order By USER_TYPE_ID";

        DataTable dt = DBUtil.ExecuteDataTable(cmd);
        foreach (DataRow dr in dt.Rows)
        {
            list.Add(new tbl_user_type()
            {
                USER_TYPE_ID = Convert.ToInt32(dr["USER_TYPE_ID"]),
                USER_TYPE = dr["USER_TYPE"].ToString(),
                IS_ACTIVE = Convert.ToBoolean(dr["IS_ACTIVE"]),
                CREATED_BY = dr["CREATED_BY"].ToString(),
                CRETED_DATE = dr["CRETED_DATE"].toDateTimeWithoutError(),
                UPDATED_BY = dr["UPDATED_BY"].ToString(),
                UPDATED_DATE = dr["UPDATED_DATE"].toDateTimeWithoutError()
            });
        }

        return list;
    }



    public int insert(String USER_TYPE, bool IS_ACTIVE, String CREATED_BY, DateTime CRETED_DATE)
    {
        int i = 0;
        string sql = @"Insert into tbl_user_type(USER_TYPE, IS_ACTIVE, CREATED_BY, CRETED_DATE)
                        values(@USER_TYPE, @IS_ACTIVE, @CREATED_BY, @CRETED_DATE)";

        MySqlCommand cmd = new MySqlCommand(sql);

        cmd.Parameters.AddWithValue("@USER_TYPE", USER_TYPE);
        cmd.Parameters.AddWithValue("@IS_ACTIVE", IS_ACTIVE);
        cmd.Parameters.AddWithValue("@CREATED_BY", CREATED_BY);
        cmd.Parameters.AddWithValue("@CRETED_DATE", CRETED_DATE);

        i = DBUtil.ExecuteNonQuery(cmd);
        return i;
    }



    public int update(int USER_TYPE_ID, String USER_TYPE, bool IS_ACTIVE, String UPDATED_BY, DateTime UPDATED_DATE)
    {
        int i = 0;
        string sql = @"Update tbl_user_type SET USER_TYPE=@USER_TYPE, IS_ACTIVE=@IS_ACTIVE, UPDATED_BY=@UPDATED_BY, UPDATED_DATE=@UPDATED_DATE WHERE USER_TYPE_ID=@USER_TYPE_ID";

        MySqlCommand cmd = new MySqlCommand(sql);

        cmd.Parameters.AddWithValue("@USER_TYPE_ID", USER_TYPE_ID);
        cmd.Parameters.AddWithValue("@USER_TYPE", USER_TYPE);
        cmd.Parameters.AddWithValue("@IS_ACTIVE", IS_ACTIVE);
        cmd.Parameters.AddWithValue("@UPDATED_BY", UPDATED_BY);
        cmd.Parameters.AddWithValue("@UPDATED_DATE", UPDATED_DATE);

        i = DBUtil.ExecuteNonQuery(cmd);
        return i;
    }



    public int delete(int USER_TYPE_ID)
    {
        int i = 0;
        string sql = "Delete FROM tbl_user_type WHERE USER_TYPE_ID=@USER_TYPE_ID";

        MySqlCommand cmd = new MySqlCommand(sql);

        cmd.Parameters.AddWithValue("@USER_TYPE_ID", USER_TYPE_ID);

        i = DBUtil.ExecuteNonQuery(cmd);
        return i;
    }



}